

// @IonicPage()
// @Component({
//   selector: 'page-browse-shop',
//   templateUrl: 'browse-shop.html',
// })
// export class BrowseShopPage {

//   constructor(public navCtrl: NavController, public navParams: NavParams) {
//   }

//   ionViewDidLoad() {
//     console.log('ionViewDidLoad BrowseShopPage');
//   }

// }






import { Component, Injector } from '@angular/core';
import { IonicPage } from 'ionic-angular';
import { BasePage } from "../basePage";
import { UserService } from '../../providers/UserService';
import { StorageService } from './../../providers/StorageService';
import { PIC_URL } from "./../../providers/Config";

/**
 * Generated class for the ShopSearchPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-browse-shop',
  templateUrl: 'browse-shop.html',
})
export class BrowseShopPage extends BasePage {
  showServeStyle: boolean;
  showGaming: boolean;
  showToppings: boolean;
  showSearch: boolean;
  showData: boolean;
  nail_id: any;
  search: any;
  service_id: any;
  showAttentio: boolean;
  showAttention: any;
  ShopArr = [];
  nailStyleArr = [];
  modalCtrl: any;
  userinfo: any;

  /*搜素栏需要用到的数据*/
  myInput: string;
  searchGetTheFocus:Number = 0;

  picrooturl: any;  /*用来保存图片服务器的地址*/
  /**关注 */
  attentionNum: boolean;
  attentionVo = {
    focused_id: null,
    user_id: null
  }
  /**店铺列表参数 */
  GetTabBarShopsAPIVo = {
    local_city: 420100,
    user_id: null,
    /* 在搜索合作店铺的时候 需要传入 search_type = 10 来标明是 合作店铺选项*/ 
    search_type: 10,
    nail_id:null,
   
  }

  picture: string;

  /**搜索传参数绑定 */
  toppings: any;
  gaming: any;
  serveStyle: any;

  constructor(injector: Injector,
    public userService: UserService,
    public storage: StorageService) {
    super(injector);
    this.picture = PIC_URL;
  }


  ionViewDidLoad() {
    console.log('ionViewDidLoad BrowseShopPage');
    
    /*跳转过来携带参数 携带了 nail_id */ 
    console.log(this.navParams.get("nail_id"));

    this.GetTabBarShopsAPIVo.nail_id = this.navParams.get('nail_id');


    this.attentionNum = true;
    // this.GetTabBarShopsAPI(0);
    this.userinfo = this.storage.read('userinfo');

    if(this.userinfo === null){
      this.attentionVo.user_id = this.GetTabBarShopsAPIVo.user_id = "";
    }else{
      this.attentionVo.user_id = this.GetTabBarShopsAPIVo.user_id = this.userinfo.user_id;
      for (let key in this.userinfo) {
        if (key == "user_id" && this.GetTabBarShopsAPIVo.user_id != null) {
          this.showAttentio = true;
          this.GetTabBarShopsAPI( "");
          return;
        } else {
          this.showAttentio = false;
          return;
        }
      }
    }
  }
  /*每次都要执行的函数*/
  ionViewDidEnter(){
    this.searchGetTheFocus = 0;
  }
      
  /*设置搜索input的事件*/
  getFocus($event){
    this.searchGetTheFocus = 1;
  }
  loseFocus(){
    if(this.myInput == null) this.searchGetTheFocus = 2;
    else if(this.myInput=='') this.searchGetTheFocus = 2;
  }
  getTheKeyDown($event){
    if($event.keyCode == '13'){
      console.log("搜索");
      console.log(this.myInput);
      this.myInput = '';
    }
  }  





  /**跳转 到美甲店铺 */
  toShopDetail(shop_id) {
    let modal = this.modalCtrl.create('NaiShopDetailPage', { user_id: this.attentionVo.user_id, shop_id: shop_id });
    modal.present();
  }
  /**跳转 到立即购买 */
  toShopInfo(id,shop_id) {
    this.service_id = id;
    // this.navCtrl.push("ShopInfoPage", { "id": this.service_id });//不要删了，
    let model = this.modalCtrl.create("ShopInfoPage", { "id": this.service_id,"shop_id":shop_id });
    model.present();
  }
  /**关注 */
  async unsetAttention(event, is_focus, shop_id) {
    if(this.userinfo == null){
      this.showAlert("您当前未登录，请登录后操作！")
      return;
    }
    this.attentionVo.focused_id = shop_id;
    let res = await this.userService.dofocusAPI(this.attentionVo);
    console.log(res);
    console.log(this.GetTabBarShopsAPIVo.search_type);
    this.GetTabBarShopsAPI(this.GetTabBarShopsAPIVo.search_type);
    if (res.code == 1) {
      let toast = this.toastCtrl.create({
        message: res.msg,
        duration: 3000,
        position: 'top',
      })
      toast.present();
    }
  }


  /**获取美甲店铺列表 */
  async GetTabBarShopsAPI(search) {
    this.search = search;
    this.ShopArr = [];
    if (search==1||search==2||search==3||search==4) {
      this.showToppings=false;
      this.showGaming=true;
      this.showServeStyle=true;
    } else if (search==5||search==6||search==7) {
      this.showToppings=true;
      this.showGaming=false;
      this.showServeStyle=true;
    } else if (search==8||search==9) {
      this.showToppings=true;
      this.showGaming=true;
      this.showServeStyle=false;
    } else {
      this.showToppings=true;
      this.showGaming=true;
      this.showServeStyle=true;
    }
    console.log(this.GetTabBarShopsAPIVo.search_type);
    console.log(this.GetTabBarShopsAPIVo);
   

    /**无搜索条件提示 */
    let result = await this.userService.doGetTabBarShopsAPI(this.GetTabBarShopsAPIVo);
    console.log(result.data);
    console.log(result);

    if (result.error_code == 0) {
      this.showData = true;
      this.ShopArr = result.data;
      return;
    } else if (result.error_code == 1001) {
      this.showData = false;
      let toast = this.toastCtrl.create({
        message: result.reason,
        duration: 3000,
        position: 'top'
      });
      toast.present();
      return;
    }
    console.log(this.nailStyleArr);
  }
}
